﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebServer.Models;
using WebServer.DBAccess;
using System.Runtime.Caching;

namespace WebServer.Biz
{
    public class WebConfigurationBiz
    {
        #region 网站设置：查询，修改

        /// <summary>
        /// 网站配置
       /// </summary>
       /// <param name="Fn">True-更新缓存，False-缓存</param>
       /// <param name="Show">0-全部显示</param>
       /// <returns></returns>
        public WebConfiguration WebConfigurationInfo(bool Fn, int Show)
        {
            WebConfiguration entity = new WebConfiguration();
            //entity = new WebConfigurationDA().WebConfigurationInfo(Show);

            CacheItemPolicy policy = new CacheItemPolicy();
            policy.AbsoluteExpiration = DateTime.Now.AddYears(1);
            ObjectCache cache = MemoryCache.Default;

            if (Fn == true)
            {
                entity = new WebConfiguration();
                entity = new WebConfigurationDA().WebConfigurationInfo(Show);
                cache.Set("MNWebConfiguration", entity, policy);
            }
            else
            {
                entity = cache["MNWebConfiguration"] as WebConfiguration;
                if (entity == null)
                {
                    entity = new WebConfiguration();
                    entity = new WebConfigurationDA().WebConfigurationInfo(Show);
                    cache.Set("MNWebConfiguration", entity, policy);
                }
            }
            return entity;
        }


        /// <summary>
        /// 修改网站配置
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int UWebConfiguration(WebConfiguration entity)
        {
            int result = 0;
            result = new WebConfigurationDA().UWebConfiguration(entity);
            return result;
        }
        #endregion
    }
}
